#include <iostream>
#include <cstdio>
#include <cerrno>
#include <cstring>
#include <cassert>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "head.hpp"

int main(){
    umask(0);
    int n = mkfifo(pipeName.c_str(), mode);
    if(n != 0){
        cout << errno << " : " << strerror(errno) << endl;
        return 1;
    }
    cout << "creat fifo file success" << endl;

    int wfd = open(pipeName.c_str(), O_WRONLY);
    if(wfd < 0){
        cout << errno << " : " << strerror(errno) << endl;
        return 2;
    }
    cout << "open fifo success, begin ipc" << endl;

    const string str = "i am process A";
    size_t m = write(wfd, str.c_str(), strlen(str.c_str()));
    assert(m >= 0);
    (void)m;

    close(wfd);
    return 0;
}